<template>
    <div style="height:100%;background-color:#f4f7fa ">
        <div style="position:relative;">
            <el-steps :active="1" align-center style="padding-top:20px">
                <el-step title="填写出库申请"></el-step>
                <el-step title="审核出库申请"></el-step>
                <el-step title="创建出库计划"></el-step>
                <el-step title="车辆到达"></el-step>
                <el-step title="开始作业"></el-step>
                <el-step title="作业完成"></el-step>
                <el-step title="离开园区"></el-step>
            </el-steps>
            <el-button type="primary" :loading="this.bLoading" size="mini" style="margin: 10px 0 0 30px" @click="cretedInfoDtail(0)">保存
            </el-button>
            <el-button type="primary" :loading="this.bLoading" size="mini" style="margin: 10px 0 0 10px" @click="cretedInfoDtail(1)">保存并提交
            </el-button>
            <el-button type="primary" @click="onIsShows" size="mini"
                       style="position:absolute;top:80px;right:0px;margin: 10px 30px 0 0">返回
            </el-button>
            <el-card style="margin:7px 30px 10px">
                <!-- <div slot="header">出库信息</div> -->
                <div>
                    <el-row>
                        <el-col :span="0.8" style="line-height:40px">仓库：</el-col>
                        <el-col :span="3">
                            <el-input style="margin-top:5px"
                                      v-model="wareList.filter(item => item.id == this.$route.params.menuActiveName)[0].whName"
                                      size="mini" :disabled="true" placeholder="请输入内容"
                                      v-if='this.$route.params.menuActiveName'></el-input>
                            <el-input style="margin-top:5px"
                                      v-model="wareList.filter(item => item.id == this.$props.menuActiveName)[0].whName"
                                      size="mini" :disabled="true" placeholder="请输入内容" v-else></el-input>
                        </el-col>
<!--                        <el-col :span="0.8" style="line-height:40px;margin-left:10px">货权方：</el-col>-->
<!--                        <el-col :span="3">-->
<!--                            <el-input style="margin-top:5px" v-model="cargoOwner.dictName" :disabled="true" size="mini"-->
<!--                                      placeholder="请输入内容"></el-input>-->
<!--                        </el-col>-->
                        <!-- <el-col :span="1.4" style="line-height:40px;margin-left:10px">结算客户：</el-col>
                        <el-col :span="3">
                          <el-input v-model="settlementCustomer" placeholder="请输入内容"></el-input>
                        </el-col> -->
                      <el-col :span="0.8" style="line-height:40px;margin-left:10px">货权方：</el-col>
                      <el-col :span="4">
                        <!-- <el-input size="mini" style="margin-top:5px" v-model="cargoOwner.dictName" :disabled="false" placeholder="请输入货权方全称" @blur="cargoOwnerBlur"></el-input> -->
                        <el-select
                          v-model="selectCustomer"
                          filterable
                          size="mini"
                          style="width: 100%; margin-top: 5px"
                          @change="selectCustomerChange"
                        >
                          <el-option
                            v-for="item in customerInfoList"
                            :key="item.customerPartyID"
                            :value="item.customerPartyID"
                            :label="item.customerPartyName"
                          />
                        </el-select>
                        <span v-if="!isCustomerNameInWMS" style="color: red;">WMS中不存在此客户</span>
                      </el-col>
                      <template v-if="!isshow">
                        <el-col :span="1.4" style="line-height:40px;margin-left:10px">结算客户：</el-col>
                            <el-col :span="4">
                                <!-- <el-input size="mini" style="margin-top:5px" v-model="settlementCustomer" placeholder="请输入结算客户"></el-input> -->
                                <el-select
                                v-model="settlementCustomer"
                                filterable
                                size="mini"
                                style="width: 100%; margin-top: 5px"
                                >
                                <el-option
                                    v-for="item in customerInfoList"
                                    :key="item.customerPartyID"
                                    :value="item.customerPartyID"
                                    :label="item.customerPartyName"
                                />
                                </el-select>
                            </el-col>
                      </template>
                    </el-row>
                </div>
            </el-card>
            <el-card style="margin:10px 30px">
                <div>
                    <col>
                    <span style="font-size:16px;font-weight:700;margin-right:15px;">出库车辆信息</span></col>
                    <el-button type="primary" size="mini" @click="boxInformation"
                               :disabled="this.editStatus == 'create'">新增
                    </el-button>
                    <el-button type="primary" size="mini" @click="batchDelete"
                               :disabled="!this.multipleSelection.length > 0">批量删除
                    </el-button>
                    <!-- <el-button type="primary" size="mini" >导出模板</el-button>
                    <el-button type="primary" size="mini" >导入</el-button> -->
                    <el-table
                        :data="tableData.tableInfo"
                        @row-click="handleOnChange"
                        :header-cell-style="{'font-weight': 300,'color': '#111'}"
                        highlight-current-row
                        @selection-change="handleSelectionChange"
                        ref="multipleTables"
                        style="width: 100%">
                        <el-table-column
                            type="selection"
                            width="55">
                        </el-table-column>
                        <el-table-column
                            v-for="item in tableData.cloumns"
                            :key="item.prop"
                            :prop="item.prop"
                            :render-header="(h,obj) => addRedStar(h, obj, item.isWrited)"
                            :label="item.label"
                            align="center"
                            :width="item.width">
                            <template slot-scope="scope">
                                <div v-if="item.type == 'input'">
                                    <el-input v-model="scope.row[item.prop]" size="mini" placeholder="请输入内容"></el-input>
                                </div>
                                <div v-else-if="item.type == 'select'">
                                    <el-select v-model="scope.row[item.prop]" size="mini" placeholder=""
                                               @change="changesInfo">
                                        <el-option
                                            v-for="item in businessList"
                                            :key="item.id"
                                            :label="item.dictName"
                                            :value="item.dictValue">
                                        </el-option>
                                    </el-select>
                                </div>
                                <div v-else-if="item.type == 'date'">
                                    <el-date-picker
                                        v-model="scope.row[item.prop]"
                                        type="date"
                                        size="mini"
                                        placeholder="选择日期">
                                    </el-date-picker>
                                </div>
                                <div v-else-if="item.type == 'radio'">
                                    <el-checkbox v-model="scope.row[item.prop]"></el-checkbox>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column fixed="right" label="操作" width="200" align="center">
                            <template slot-scope="scope">
                                <div style="display: flex;justify-content: center">
                                    <el-button type="text" size="mini"
                                               @click.native.prevent="boxCretedInfo(scope.$index,tableData.tableInfo)">
                                        <span style="color:#5c68ee">新增货物信息</span></el-button>
                                    <el-button type="text" size="mini"
                                               @click.native.prevent="boxDelete(scope,tableData.tableInfo)"
                                               v-if="editStatus != 'create'" style="color:#5c68ee">删除
                                    </el-button>
                                    <el-button type="text" size="mini"
                                               @click.native.prevent="boxDelete(scope,tableData.tableInfo)"
                                               v-if="editStatus == 'create'" disabled>删除
                                    </el-button>
                                </div>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
            </el-card>
            <el-card style="margin:10px 30px">
                <div>
                    <!-- <el-button type="primary" size="mini" @click="goodsInformation">新增</el-button> -->
                    <col><span style="font-size:16px;font-weight:700;margin-right:15px;">货物信息</span></col>
                    <el-button type="primary" size="mini" @click="batchDeletes"
                               :disabled="!this.multipleSelections.length > 0">批量删除
                    </el-button>
                    <Checkbox v-model="loadingInSequence" style="margin-left: 20px">按序装车</Checkbox>
                    <el-table
                        ref="multipleTable"
                        :header-cell-style="{'font-weight': 300,'color': '#111'}"
                        :data="tableData.tableInfoList"
                        @selection-change="handleSelectionChanges"
                        style="width: 100%">
                        <el-table-column
                            type="selection"
                            width="55">
                        </el-table-column>
                        <el-table-column
                            v-for="item in tableData.goodsCloumns"
                            :key="item.prop"
                            align="center"
                            :prop="item.prop"
                            :label="item.label"
                            :width="item.width">
                        </el-table-column>
                        <el-table-column label="出库数量" prop="totalQty" width="100" align="center">
                            <template slot-scope="scope">
                                <InputNumber v-model="scope.row['totalQtyNew']" :min="0"></InputNumber>
                            </template>
                        </el-table-column>
                        <el-table-column label="是否抄码">
                            <template slot-scope="scope">
                                <div>
                                    <el-checkbox v-model="scope.row['isScanSn']" true-label="1" false-label="0"
                                                 @change="isScanSnChange(scope.row)"></el-checkbox>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column label="抄码件数">
                            <template slot-scope="scope">
                                <div>
                                    <el-input v-model="scope.row['codeQty']" size="mini" placeholder="0"
                                              :disabled="(scope.row['isScanSn'] == '0')"></el-input>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column fixed="right" width="140" label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button type="text" size="mini" @click.native.prevent="boxDtailDelete(scope)"><span
                                    style="color:#4f68e8">删除</span></el-button>
                                <el-button v-if="loadingInSequence" type="text" size="mini" style="color: #4f68e8"
                                           @click.native.prevent="handleUp(scope.$index)">上移
                                </el-button>
                                <el-button v-if="loadingInSequence" type="text" size="mini" style="color: #4f68e8"
                                           @click.native.prevent="handleUp(scope.$index)">下移
                                </el-button>
                            </template>
                        </el-table-column>
                        <el-table-column
                            width="100"
                            type="index"
                            align="center"
                            label='装车顺序'
                            v-if="loadingInSequence">
                        </el-table-column>
                    </el-table>
                </div>
            </el-card>
            <el-card style="margin:10px 30px">
                <attachment-model ref="attachmentRef" :url="`/api/wms_file/customerUpload`" :select-row.sync="selectRow" :menu-active-name="menuActiveName" :wms-url="wmsUrl" @check-data="checkData" @refresh-file-list="refreshFileList"/>
            </el-card>
            <Modal
                v-model="outPlanInfoShow"
                title="新增出库单据"
                width="80%"
                height="70%"
            >
                <div slot="footer">
                    <Button type="text" style="color: #000;" @click="outPlanInfoShow = false">取消</Button>
                    <Button type="primary" class="btn-warning" @click="goodsInformation">确定</Button>
                </div>
                <div style="margin-bottom:10px">
                    <p style="font-weight: 700; font-size: 14px;">备选货物</p>
                    <el-table
                        height="280"
                        style="width: 100%;font-size:12px"
                        :header-cell-style="{'font-weight': 300,'color': '#111',background:'rgb(242,245,249)',padding: '3px'}"
                        :data="searchInfo">
                        <el-table-column
                            type="index"
                            label="序号"
                            align="center"
                            width="60">
                        </el-table-column>
                        <el-table-column
                            v-for="item in tableData.AddColumns"
                            :key="item.prop"
                            :prop="item.prop"
                            :width="item.width"
                            :label="item.label"
                            align="center"
                            :fixed="item.fixed">
                            <el-table-column :width="item.width" v-if="item.type" :prop="item.prop" align="center"
                                             :formatter="item.formatter">
                                <template slot="header" slot-scope="scope">
                                    <Input
                                        v-if="item.prop === 'batchAttr07'"
                                        v-model="searchTableData['batchAttr07']"
                                        placeholder="输入关键字搜索"
                                        @on-enter="getStockListByOwnerCode"/>
                                    <Input
                                        v-if="item.prop === 'matName'"
                                        v-model="searchTableData['matName']"
                                        placeholder="输入关键字搜索"
                                        @on-enter="getStockListByOwnerCode"/>
                                    <Input
                                        v-if="item.prop === 'country'"
                                        v-model="searchTableData['country']"
                                        placeholder="输入关键字搜索"
                                        @on-enter="getStockListByOwnerCode"/>
                                    <Input
                                        v-if="item.prop === 'factoryCode'"
                                        v-model="searchTableData['factoryCode']"
                                        placeholder="输入关键字搜索"
                                        @on-enter="getStockListByOwnerCode"/>
                                    <Input
                                        v-if="item.prop === 'batchAttr08'"
                                        v-model="searchTableData['batchAttr08']"
                                        placeholder="输入关键字搜索"
                                        @on-enter="getStockListByOwnerCode"/>
                                    <Input
                                        v-if="item.prop === 'wmsBatchNum'"
                                        v-model="searchTableData['wmsBatchNum']"
                                        placeholder="输入关键字搜索"
                                        @on-enter="getStockListByOwnerCode"/>
                                    <el-select clearable v-model="searchTableData['settlementCustomerName']" value=""
                                                :popper-append-to-body="false"
                                                size="mini" placeholder="" v-if="item.prop === 'settlementCustomerName'"
                                                @change="getStockListByOwnerCode">
                                        <el-option
                                            v-for="item in allOwner"
                                            :key="item.id"
                                            :label="item.settlementCustomerName"
                                            :value="item.settlementCustomer">
                                        </el-option>
                                    </el-select>
                                    <DatePicker placeholder="请选择" transfer type="daterange" split-panels
                                                v-if="item.prop == 'dateInto'" style="width:140px"
                                                v-model="searchTableData['dateInto']"
                                                @on-change="getStockListByOwnerCode"></DatePicker>
                                    <DatePicker placeholder="请选择" transfer type="daterange" split-panels
                                                v-if="item.prop == 'dateGen'" style="width:140px"
                                                v-model="searchTableData['dateGen']"
                                                @on-change="getStockListByOwnerCode"></DatePicker>
                                    <DatePicker placeholder="请选择" transfer type="daterange" split-panels
                                                v-if="item.prop == 'dateExpire'" style="width:140px"
                                                v-model="searchTableData['dateExpire']"
                                                @on-change="getStockListByOwnerCode"></DatePicker>
                                    <el-select clearable v-model="searchTableData['matTypCode']" size="mini"
                                                :popper-append-to-body="false"
                                                placeholder="" v-if="item.prop === 'matTypName'"
                                                @change="getStockListByOwnerCode">
                                        <el-option
                                            v-for="item in categoryList"
                                            :key="item.id"
                                            :label="item.dictName"
                                            :value="item.dictValue">
                                        </el-option>
                                    </el-select>
                                    <el-select clearable v-model="searchTableData['whName']" size="mini" placeholder=""
                                                :popper-append-to-body="false"
                                                v-if="item.prop === 'whName'" @change="getStockListByOwnerCode">
                                        <el-option
                                            v-for="item in whList"
                                            :key="item.id"
                                            :label="item.label"
                                            :value="item.value">
                                        </el-option>
                                    </el-select>
                                    <el-select clearable v-model="searchTableData['mscAuthentication']" size="mini"
                                                :popper-append-to-body="false"
                                                placeholder="" v-if="item.prop === 'mscAuthentication'"
                                                @change="getStockListByOwnerCode">
                                        <el-option
                                            v-for="item in mscAuthenticationList"
                                            :key="item.id"
                                            :label="item.label"
                                            :value="item.value">
                                        </el-option>
                                    </el-select>
                                    <el-select clearable v-model="searchTableData['stgTypText']" size="mini"
                                                :popper-append-to-body="false"
                                                placeholder="" v-if="item.prop === 'stgTypText'"
                                                @change="getStockListByOwnerCode">
                                        <el-option
                                            v-for="item in allStgData"
                                            :key="item.id"
                                            :label="item.stgTypText"
                                            :value="item.stgTypCode">
                                        </el-option>
                                    </el-select>
                                    <el-select clearable v-model="searchTableData['goodsBondedProperty']" size="mini"
                                                :popper-append-to-body="false"
                                                placeholder="" v-if="item.prop === 'goodsBondedProperty'"
                                                @change="getStockListByOwnerCode">
                                        <el-option
                                            v-for="item in goodsBondedPropertyList"
                                            :key="item.id"
                                            :label="item.label"
                                            :value="item.value">
                                        </el-option>
                                    </el-select>
                                    <el-select clearable v-model="searchTableData['supervisionStatus']" size="mini"
                                                :popper-append-to-body="false"
                                                placeholder="" v-if="item.prop === 'supervisionStatus'"
                                                @change="getStockListByOwnerCode">
                                        <el-option
                                            v-for="item in supervisionStatusList"
                                            :key="item.id"
                                            :label="item.label"
                                            :value="item.value">
                                        </el-option>
                                    </el-select>
                                    <el-select clearable v-model="searchTableData['productStatus']" size="mini"
                                                :popper-append-to-body="false"
                                                placeholder="" v-if="item.prop === 'productStatus'"
                                                @change="getStockListByOwnerCode">
                                        <el-option
                                            v-for="item in productStatusSelectList"
                                            :key="item.id"
                                            :label="item.label"
                                            :value="item.value">
                                        </el-option>
                                    </el-select>
                                </template>
                            </el-table-column>
                        </el-table-column>
                        <el-table-column label="可出库数量" fixed="right" prop="availableQty" align="center" width="100">
                        </el-table-column>
                        <el-table-column label="操作" fixed="right" width="100" align="center">
                            <template slot-scope="scope">
                                <el-button
                                    v-if="scope.row['availableQty'] > 0"
                                    size="mini" type="text"
                                    @click.native.prevent="addHandler(scope.$index, scope.row)"><span
                                    style="color:#5c68ee">添加</span></el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <Page style="margin-top:10px" :total="total" size="small" show-elevator show-sizer
                        @on-change="Pagechange" @on-page-size-change="pageSizeChange"></Page>
                </div>
                <div>
                    <p style="font-weight: 700; font-size: 14px;">已选货物</p>
                    <el-table
                        :data="selectInfo"
                        height="240"
                        style="width: 100%;font-size:12px"
                        :header-cell-style="{'font-weight': 300,'color': '#111',background:'rgb(242,245,249)',padding: '5px'}"
                    >
                        <el-table-column
                            type="index"
                            label="序号"
                            width="60">
                        </el-table-column>
                        <el-table-column v-for="item in tableData.selectColumns"
                                         :key="item.prop"
                                         :prop="item.prop"
                                         :width="item.width"
                                         :label="item.label"
                                         :formatter="item.formatter"
                                         align="center"
                        >
                        </el-table-column>
                        <el-table-column label="出库数量" fixed="right" prop="totalQty" width="120" align="center">
                            <template slot-scope="scope">
                                <InputNumber v-model="scope.row['totalQtyNew']" :value="scope.row['availableQty']"
                                             :min="0"></InputNumber>
                            </template>
                        </el-table-column>
                        <el-table-column fixed="right" width="100" label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button type="text" size="mini"
                                           @click.native.prevent="selectInfoDelete(scope.$index, scope.row)"><span
                                    style="color:#5c68ee">删除</span></el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
            </Modal>
        </div>
    </div>
</template>

<script>
import {
    getBoxInfoWarehousing, getBusinessInfo, getCategoryInfo,
    getBusinessInfos, createOutStockApply, deleteApplyAndApplyDetail,
    getStockListByOwnerCodeForLenglian, getAllStgData, updateOutStockApply,
    selectCustomerInfoByDto, getOwnerCodeListByStock
} from '@/api/planInfo.js'
import baseCodeApi from '@/api/baseCode';
import {v4 as uuidv4} from 'uuid'
import _ from 'lodash'
import AttachmentModel from '@/view/component/attachment/index.vue'
import {getByCustomerType} from "@/api/outInto";

export default {
    components: {
        AttachmentModel
    },
    props: {
        menuActiveName: {
            type: Number,
            default: null
        },
        wmsUrl: {
            type: String,
            default: ''
        },
        wareList: {
            type: Array,
            default: () => [{}]
        },
        editItem: {
            type: Object,
            default: () => {
            }
        },
        editItemWarehousing: {
            type: Object,
            default: () => {
            }
        },
        ccisCustomerCode: {
            type: String,
            default: ''
        },
        editStatus: {
            type: String,
            default: ''
        }
    },
    data() {
        return {
          isshow:window.localStorage.getItem('EditInfocode'),
          wmsCustomerList: [],
          selectCustomer: '',
          selectCustomerCode: '',
            allOwner: [],
            tableDataCK: [],
            outQty: '',
            bLoading: false,
            productStatusList: [
                {
                    value: '1',
                    label: '是'
                },
                {
                    value: '0',
                    label: '否'
                }
            ],
            outPlanInfoShow: false,
            loadingInSequence: false,
            tableData: {
                totalQty: '',
                tableInfo: [],
                tableInfoList: [],
                cloumns: [{
                    prop: "carNo",
                    label: "提货车号",
                    type: 'input'
                }, {
                    prop: "driver",
                    label: "提货司机",
                    type: 'input'
                }, {
                    prop: "tel",
                    label: "司机联系方式",
                    type: 'input'
                },
                    {
                        prop: 'outEstimateDate',
                        label: '预计提货时间',
                        type: 'date'
                    }, {
                        prop: "remark",
                        label: "备注",
                        type: 'input'
                    },],
                goodsCloumns: [{
                    prop: "batchAttr07",
                    label: "箱号"
                }, {
                    prop: "matTypName",
                    label: "品类"
                }, {
                    prop: "matName",
                    label: "品名"
                }, {
                    prop: "country",
                    label: "国别"
                }, {
                    prop: "factoryCode",
                    label: "厂号"
                }, {
                    prop: "dateInto",
                    label: "入库日期",
                    width: '190'
                }, {
                    prop: "availableQty",
                    label: "可出库件数",
                }],
                AddColumns: [{
                    prop: 'batchAttr07',
                    label: '箱号',
                    type: 'input',
                    width: '160',
                }, {
                    prop: 'matName',
                    label: '品名',
                    width: '160',
                    type: 'input'
                }, {
                    prop: 'matTypName',
                    label: '品类',
                    width: '160',
                    type: 'select'
                }, {
                    prop: 'country',
                    label: '国别',
                    width: '160',
                    type: 'input'
                }, {
                    prop: 'factoryCode',
                    label: '厂号',
                    width: '160',
                    type: 'input'
                }, {
                    prop: 'batchAttr08',
                    label: '提单号',
                    width: '160',
                    type: 'input'
                }, {
                    prop: 'goodsBondedProperty',
                    label: '保税性质',
                    type: 'select',
                    width: '160',
                    formatter: (row) => {
                        if (row.goodsBondedProperty == 0) {
                            return '保税'
                        } else {
                            return '一般贸易'
                        }
                    }
                }, {
                    prop: 'supervisionStatus',
                    label: '质押状态',
                    type: 'select',
                    width: '160',
                    formatter: (row) => {
                        if (row.supervisionStatus == 0) {
                            return '未质押'
                        } else {
                            return '已质押'
                        }
                    }
                }, {
                    prop: 'dateGen',
                    type: 'dateGen',
                    label: '生产日期',
                    width: '160'
                }, {
                    prop: 'dateExpire',
                    type: 'dateExpire',
                    label: '失效日期',
                    width: '160'
                },
                    {
                        prop: 'dateInto',
                        label: '入库时间',
                        width: '160',
                        type: 'date'
                    }, {
                        prop: 'settlementCustomerName',
                        type: 'settlementCustomerName',
                        label: '当前结算客户',
                        width: '240',
                    }, {
                        prop: 'totalQty',
                        label: '总库存件数',
                        width: '160'
                    }],
                tableList: [{
                    cargoOwner: "2018763",
                    settlementCustomer: "人工搬运",
                    billOfLandingNo: "UIUI74125896",
                    containerNum: "RQ",
                    containerSize: "40",
                    shipName: "",
                    voyageNum: "",
                    batchNum: "",
                    contractNo: "",
                    inEstimateDate: "",
                    carNo: "",
                    driver: "",
                    driverTel: "",
                    intoSeparationChargeSign: "",
                    authenticateFlag: "",
                    remark: "",
                    list: [
                        {
                            matCode: "20210925022",
                            matName: "现场测试品名",
                            matTypCode: "9999",
                            county: "",
                            factoryCode: "",
                            packFormat: "",
                            orderQty: 1,
                            orderWeight: 2,
                            productStatus: "",
                            dateGen: "",
                            validatePeriod: "",
                            ifCodeReading: "",
                            codeQty: ""
                        }
                    ]
                }],
                selectColumns: [{
                    prop: 'batchAttr07',
                    label: '箱号',
                    type: 'input',
                    width: '160',
                }, {
                    prop: 'matName',
                    label: '品名',
                    width: '160',
                    type: 'input'
                }, {
                    prop: 'matTypName',
                    label: '品类',
                    width: '160',
                    type: 'select'
                }, {
                    prop: 'country',
                    label: '国别',
                    width: '160',
                    type: 'input'
                }, {
                    prop: 'factoryCode',
                    label: '厂号',
                    width: '160',
                    type: 'input'
                }, {
                    prop: 'batchAttr08',
                    label: '提单号',
                    width: '160',
                    type: 'input'
                }, {
                    prop: 'goodsBondedProperty',
                    label: '保税性质',
                    type: 'select',
                    width: '160',
                    formatter: (row) => {
                        if (row.goodsBondedProperty == 0) {
                            return '保税'
                        } else {
                            return '一般贸易'
                        }
                    }
                }, {
                    prop: 'supervisionStatus',
                    label: '质押状态',
                    type: 'select',
                    width: '160',
                    formatter: (row) => {
                        if (row.supervisionStatus == 0) {
                            return '未质押'
                        } else {
                            return '已质押'
                        }
                    }
                }, {
                    prop: 'dateGen',
                    type: 'dateGen',
                    label: '生产日期',
                    width: '160'
                }, {
                    prop: 'dateExpire',
                    type: 'dateExpire',
                    label: '失效日期',
                    width: '160'
                },
                    {
                        prop: 'dateInto',
                        label: '入库时间',
                        width: '160',
                        type: 'date'
                    }, {
                        prop: 'settlementCustomerName',
                        type: 'settlementCustomerName',
                        label: '当前结算客户',
                        width: '240',
                    },
                    {
                        prop: 'totalQty',
                        label: '总库存件数',
                        width: '130'
                    }]
            },
            searchInfo: [],
            selectInfo: [],
            searchTableData: {
                whName: '',
                filterValue: '',
                stgTypCode: '',
                batchAttr07: '',
                matName: '',
                matTypCode: '',
                country: '',
                mscAuthentication: '',
                goodsBondedProperty: '',
                supervisionStatus: '',
                wmsBatchNum: '',
                productStatus: ''
            },
            value: '',
            matCodeList: [],
            multipleSelection: [],
            multipleSelections: [],
            isCreted: false,
            settlementCustomer: '',
            businessList: [],
            categoryList: [],
            dictInfo: {},
            allStgData: [],
            cargoOwner: {
                dictName: ''
            },
            mscAuthenticationList: [
                {label: '是', value: 1},
                {label: '否', value: 0}
            ],
            goodsBondedPropertyList: [
                {label: '一般贸易', value: 1},
                {label: '保税', value: 0}
            ],
            supervisionStatusList: [
                {label: '已质押', value: 1},
                {label: '未质押', value: 0}
            ],
            productStatusSelectList: [
                {label: '正品', value: 1},
                {label: '不良品', value: 2},
                {label: '退货正品', value: 3},
                {label: '破箱', value: 4}
            ],
            whList: [
                // { label: this.wareList.filter(item => item.id == this.menuActiveName)[0].whName, value: this.wareList.filter(item => item.id == this.menuActiveName)[0].whCode}
            ],
            activeRowSelect: [],
            activeIndexSelect: '',
            codeQty: '',
            total: 0,
            page: 1,
            pageSize: 10,
            closeAdd: true,
            selectRow: null
        }
    },
    methods: {
        addRedStar(h, {column}, required) {
            if (column.property == 'carNo' || column.property == 'driver' || column.property == 'tel' || column.property == 'outEstimateDate') {
                return [
                    h('span', {style: 'color: red'}, '*'),
                    h('span', ' ' + column.label)
                ]
            } else {
                return [
                    h('span', {}, column.label)
                ]
            }
        },
        filterTime(time) {
            var date = new Date(time);
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            m = m < 10 ? "0" + m : m;
            var d = date.getDate();
            d = d < 10 ? "0" + d : d;
            var h = date.getHours();
            h = h < 10 ? "0" + h : h;
            var minute = date.getMinutes();
            minute = minute < 10 ? "0" + minute : minute;
            var s = date.getSeconds();
            s = s < 10 ? "0" + s : s;
            return y + "-" + m + "-" + d;
        },
        isScanSnChange(item) {
            this.tableData.tableInfoList.forEach(items => {
                if (items.isScanSn == '1') {
                    items.codeQty = _.cloneDeep(items.totalQtyNew)
                } else {
                    items.codeQty = 0;
                }
            })
        },
        totalQtyHandler() {
            this.selectInfo.some((selectInfoItem) => {
                console.log(selectInfoItem);
                if (selectInfoItem.totalQtyNew > selectInfoItem.availableQty) {
                    // this.$message.warning('出库数量不可大于可出库数量');
                    this.closeAdd = false
                    return true;
                } else {
                    this.closeAdd = true
                }
            })
        },
        Pagechange(page) {
            this.page = page,
                this.getStockListByOwnerCode();
        },
        pageSizeChange(pageSize) {
            this.pageSize = pageSize
            this.getStockListByOwnerCode();
        },
        swapArray(arr, index1, index2) {
            arr[index1] = arr.splice(index2, 1, arr[index1])[0];
            return arr;
        },
        handleUp(i) {
            this.swapArray(this.tableData.tableInfoList, i, i - 1);
        },
        // 下移
        handleDown(i) {
            this.swapArray(this.tableData.tableInfoList, i, i + 1);
        },
        selectCustomerInfoByDto() {
            selectCustomerInfoByDto({'ccisCustomerCode': this.selectCustomerCode }, this.$props.wmsUrl).then(({data}) => {
                this.ccisCustomerCode = data.returnData[0].customerCode
            })
        },
        addHandler(index, rows) {
          let isShowErrMag = false;
          this.selectInfo.forEach(item=>{
            if(rows.settlementCustomer!==item.settlementCustomer){
              isShowErrMag = true;
              return;
            }
          })
          if(isShowErrMag){
            this.$Message.warning('所选货物信息不允许存在多个结算客户');
            return;
          }
            this.searchInfo.splice(index, 1);
            this.selectInfo.push(rows)
            rows['totalQtyNew'] = rows.availableQty
            this.outQty = rows.totalQty;
        },
        selectInfoDelete(index, rows) {
            this.searchInfo.push(rows);
            this.selectInfo.splice(index, 1)
        },
        getStockListByOwnerCode() {
            this.searchInfo = []
            let body = {
                filterList: [
                    {
                        filterKey: "whCode",
                        filterValue: ""
                    },
                    {
                        filterKey: 'ownerCode',
                        filterValue: this.$props.ccisCustomerCode
                    },
                    {
                        filterKey: 'supervisionStatus',
                        filterValue: '0'
                    }
                ],
                filterName: [],
                stkCodeList: [],
                pageNum: this.page,
                pageSize: this.pageSize,
                pageOptionsList: [
                    50,
                    100,
                    200
                ],
                searchKeyOrderType: null,
                sortList: [],
                searchKey: "",
                searchOwnerCode: this.ccisCustomerCode,
                searchWhCode: '',
                searchSettlementCustomer: '',
                searchManageCompanyCode: '',
                outPlanOrderNum: ""
            }
            if (this.searchTableData.batchAttr07 !== '') {
                body.filterList.push({filterKey: 'batchAttr07', filterValue: this.searchTableData.batchAttr07})
            }
            if (this.searchTableData.settlementCustomerName) {
                body.filterList.push({
                    filterKey: 'searchSettlementCustomer',
                    filterValue: this.searchTableData.settlementCustomerName
                })
            }
            console.log(this.searchTableData, 'this.searchTableDatathis.searchTableData')
            if (this.searchTableData.dateGen && this.searchTableData.dateGen.length > 1) {
                let start
                let end
                if (this.searchTableData.dateGen[0]) {
                    start = this.$utils.timestampToDate(this.searchTableData.dateGen[0]);
                }
                if (this.searchTableData.dateGen[1]) {
                    end = this.$utils.timestampToDate(this.searchTableData.dateGen[1]);
                }


                body.filterList.push({filterKey: 'dateGenStart', filterValue: start})
                body.filterList.push({filterKey: 'dateGenEnd', filterValue: end})
            }
            if (this.searchTableData.dateInto && this.searchTableData.dateInto.length > 1) {
                let start
                let end
                if (this.searchTableData.dateInto[0]) {
                    start = this.filterTime(this.searchTableData.dateInto[0])
                }
                if (this.searchTableData.dateInto[1]) {
                    end = this.filterTime(this.searchTableData.dateInto[1])
                }
                body.filterList.push({filterKey: 'dateIntoStartDate', filterValue: start})
                body.filterList.push({filterKey: 'dateIntoEndDate', filterValue: end})
            }
            if (this.searchTableData.dateExpire && this.searchTableData.dateExpire.length > 1) {
                let start
                let end
                if (this.searchTableData.dateExpire[0]) {
                    start = this.filterTime(this.searchTableData.dateExpire[0])
                }
                if (this.searchTableData.dateExpire[1]) {
                    end = this.filterTime(this.searchTableData.dateExpire[1])
                }
                body.filterList.push({filterKey: 'dateExpireStart', filterValue: start})
                body.filterList.push({filterKey: 'dateExpireEnd', filterValue: end})
            }
            if (this.searchTableData.factoryCode) {
                body.filterList.push({filterKey: 'factoryCode', filterValue: this.searchTableData.factoryCode})
            }
            if (this.searchTableData.batchAttr08) {
                body.filterList.push({filterKey: 'batchAttr08', filterValue: this.searchTableData.batchAttr08})
            }
            if (this.searchTableData.whName !== '') {
                body.filterList.push({filterKey: 'whName', filterValue: this.searchTableData.whName})
            }
            if (this.searchTableData.filterValue !== '') {
                body.filterList.push({filterKey: 'filterValue', filterValue: this.searchTableData.filterValue})
            }
            if (this.searchTableData.stgTypCode !== '') {
                body.filterList.push({filterKey: 'stgTypCode', filterValue: this.searchTableData.stgTypCode})
            }
            if (this.searchTableData.matName !== '') {
                body.filterList.push({filterKey: 'matName', filterValue: this.searchTableData.matName})
            }
            if (this.searchTableData.matTypCode !== '') {
                body.filterList.push({filterKey: 'matTypCode', filterValue: this.searchTableData.matTypCode})
            }
            if (this.searchTableData.country !== '') {
                body.filterList.push({filterKey: 'country', filterValue: this.searchTableData.country})
            }
            if (this.searchTableData.mscAuthentication !== '') {
                body.filterList.push({
                    filterKey: 'mscAuthentication',
                    filterValue: this.searchTableData.mscAuthentication
                })
            }
            if (this.searchTableData.goodsBondedProperty !== '') {
                body.filterList.push({
                    filterKey: 'goodsBondedProperty',
                    filterValue: this.searchTableData.goodsBondedProperty
                })
            }
            if (this.searchTableData.supervisionStatus !== '') {
                body.filterList.push({
                    filterKey: 'supervisionStatus',
                    filterValue: this.searchTableData.supervisionStatus
                })
            }
            if (this.searchTableData.wmsBatchNum !== '') {
                body.filterList.push({filterKey: 'wmsBatchNum', filterValue: this.searchTableData.wmsBatchNum})
            }
            if (this.searchTableData.productStatus !== '') {
                body.filterList.push({filterKey: 'productStatus', filterValue: this.searchTableData.productStatus})
            }
            body.stockQueryType = 'outPlan'
            getStockListByOwnerCodeForLenglian(body, this.$props.wmsUrl).then(({data}) => {
                this.total = data.returnData.pageInfo.total
                this.searchInfo = data.returnData.pageInfo.list
                this.searchInfo.forEach((item) => {
                    item.dateInto = this.$utils.timestampToDate(item.dateInto);
                    item.dateGen = this.$utils.timestampToDate(item.dateGen);
                    item.dateExpire = this.$utils.timestampToDate(item.dateExpire);
                })
                this.selectInfo.forEach(item => {
                    this.searchInfo = this.searchInfo.filter(items => item.filterUniqueCode != items.filterUniqueCode)
                })
            })
            getAllStgData(this.$props.wmsUrl).then(({data}) => {
                this.allStgData = data.returnData
            })
        },
        handleEdit(index, row) {
        },
        changesInfos(event, row) {
            getBusinessInfos({matTypCode: event}, this.$props.wmsUrl).then(({data}) => {
                this.$set(row, 'matCodeList', data.returnData)
            })
        },
        changesInfo(row) {
            if (row == 'move') {
                row.tableData.cloumns = [{
                    prop: "billOfLandingNo",
                    label: "提单号",
                    type: 'input',
                    width: "200"
                }, {
                    prop: "containerNum",
                    type: 'input',
                    label: "箱号",
                    width: "150"
                }, {
                    prop: "batchAttr14",
                    label: "船名",
                    type: 'input',
                    width: "150"
                }, {
                    prop: "batchAttr16",
                    label: "航次",
                    type: 'input',
                    width: "150"
                }, {
                    prop: "batchNum",
                    label: "批次号",
                    type: 'input',
                    width: "150"
                }, {
                    prop: "batchAttr13",
                    label: "合同号",
                    type: 'input',
                    width: "150"
                }, {
                    prop: "carNo",
                    label: "送货车号",
                    type: 'input',
                    width: "150"
                }, {
                    prop: "driver",
                    label: "送货司机",
                    type: 'input',
                    width: "150"
                }, {
                    prop: "driverTel",
                    label: "送货司机联系方式",
                    type: 'input',
                    width: "200"
                }, {
                    prop: "businessType",
                    label: "业务类型",
                    type: 'select',
                    width: "150"
                }, {
                    prop: "outCarNo",
                    label: "提货车号",
                    type: 'input',
                    width: "150"
                }, {
                    prop: "outDriver",
                    label: "提货司机",
                    type: 'input',
                    width: "150"
                }, {
                    prop: "outTel",
                    label: "提货司机联系方式",
                    type: 'input',
                    width: "200"
                }, {
                    prop: "inEstimateDate",
                    label: "预计送货日期",
                    type: 'date',
                    width: "300"
                }, {
                    prop: "intoSeparationChargeSign",
                    label: "分色",
                    type: 'radio',
                    width: "100"
                }, {
                    prop: "authenticateFlag",
                    label: "出库密钥",
                    type: 'radio',
                    width: "100"
                }, {
                    prop: "remark",
                    label: "备注",
                    type: 'input',
                    width: "200"
                }]
            } else {
                this.tableData.cloumns = [{
                    prop: "billOfLandingNo",
                    label: "提单号",
                    type: 'input',
                    width: "200"
                }, {
                    prop: "containerNum",
                    type: 'input',
                    label: "箱号",
                    width: "150"
                }, {
                    prop: "batchAttr14",
                    label: "船名",
                    type: 'input',
                    width: "150"
                }, {
                    prop: "batchAttr16",
                    label: "航次",
                    type: 'input',
                    width: "150"
                }, {
                    prop: "batchNum",
                    label: "批次号",
                    type: 'input',
                    width: "150"
                }, {
                    prop: "batchAttr13",
                    label: "合同号",
                    type: 'input',
                    width: "150"
                }, {
                    prop: "carNo",
                    label: "送货车号",
                    type: 'input',
                    width: "150"
                }, {
                    prop: "driver",
                    label: "送货司机",
                    type: 'input',
                    width: "150"
                }, {
                    prop: "driverTel",
                    label: "司机联系方式",
                    type: 'input',
                    width: "150"
                }, {
                    prop: "businessType",
                    label: "业务类型",
                    type: 'select',
                    width: "150"
                }, {
                    prop: "inEstimateDate",
                    label: "预计送货日期",
                    type: 'date',
                    width: "300"
                }, {
                    prop: "intoSeparationChargeSign",
                    label: "分色",
                    type: 'radio',
                    width: "100"
                }, {
                    prop: "authenticateFlag",
                    label: "出库密钥",
                    type: 'radio',
                    width: "100"
                }, {
                    prop: "remark",
                    label: "备注",
                    type: 'input',
                    width: "200"
                }]
            }
        },
        cretedInfoDtail(statusCode) {
            try {
                this.bLoading = true
                this.$nextTick(() => {
                    if (!this.isCustomerNameInWMS) {
                      this.$Message.error('货权方WMS中不存在此客户！');
                      this.bLoading = false
                      return;
                    }
                    if (this.tableData.tableInfo.length == 0) {
                        this.$Message.warning('请输入出库车辆信息')
                        this.bLoading = false
                        return;
                    } else if (this.tableData.tableInfo[0].carNo == '') {
                        this.$Message.warning('请输入提货车号');
                        this.bLoading = false
                        return;
                    } else if (this.tableData.tableInfo[0].driver == '') {
                        this.$Message.warning('请输入提货司机');
                        this.bLoading = false
                        return;
                    } else if (this.tableData.tableInfo[0].tel == '') {
                        this.$Message.warning('请输入提货司机联系方式');
                        this.bLoading = false
                        return;
                    } else if (this.tableData.tableInfo[0].outEstimateDate == '') {
                        this.$Message.warning('请输入预计提货时间');
                        this.bLoading = false
                        return;
                    } else if (this.tableData.tableInfoList.length == 0) {
                        this.$Message.warning('请输入货物信息');
                        this.bLoading = false
                        return;
                    } else {
                        let tableInfo = _.cloneDeep(this.tableData.tableInfo);
                        let tableInfoList = _.cloneDeep(this.tableData.tableInfoList);
                        if (this.editItem) {
                            // this.tableData.tableInfo.forEach((item, index) => {
                            //   console.log(item);
                            //   item.warehousing = this.tableData.tableInfoList[0][index]
                            // })
                            // this.tableData.tableInfo.warehousing = this.tableData.tableInfoList
                            this.tableData.tableInfo[0]['list'] = this.tableData.tableInfoList
                        } else {
                            if (this.tableData.tableInfoList[0]) {
                                if (this.tableData.tableInfo.boxId === this.selectBoxId) {
                                    this.tableData.tableInfo.list = this.tableData.tableInfoList[0].list;
                                }
                            }
                        }
                        if (this.editItem) {
                            this.tableData.tableInfo[0].ccisOutStockApplyGoodsDTOList = [];
                            this.tableData.tableInfo[0].list.forEach((items, index) => {
                                if (!this.loadingInSequence) {
                                    items.seq = '0';
                                } else {
                                    items.seq = index + 1
                                }
                                console.log(this.tableData.tableInfo[0])
                                if (this.tableData.tableInfo[0].status && statusCode != 1) {
                                    this.tableData.tableInfo[0].status = this.tableData.tableInfo[0].status
                                } else {
                                    this.tableData.tableInfo[0].status = statusCode; //状态
                                }
                                this.tableData.tableInfo[0].ccisOutStockApplyGoodsDTOList.push({
                                    singleWeight: items.singleWeight,
                                    batchAttributeId: items.batchAttributeId,
                                    matName: items.matName,
                                    batchAttr07: items.batchAttr07,
                                    matTypeCode: items.matTypCode,
                                    matCode: items.matCode,
                                    county: items.country,
                                    factoryCode: items.factoryCode,
                                    productStatus: items.productStatus,
                                    inStockDate: items.dateInto,
                                    orderQty: items.totalQtyNew,
                                    isScanSn: items.isScanSn,
                                    codeQty: items.codeQty,
                                    seq: items.seq,
                                    stgTypCode: items.stgTypCode,
                                    wmsBatchNum: items.wmsBatchNum,
                                    cargoOwner: this.tableData.tableInfo.id === undefined || this.tableData.tableInfo.id === null ? this.$utils.getUserInfo().entrustingPartyCode : this.ccisCustomerCode,
                                    settlementCustomer: this.cargoOwner.customerCode
                                })
                                // if (this.loadingInSequence) {
                                //   this.tableData.tableInfo[0].ccisOutStockApplyGoodsDTOList.seq = item.index;
                                // }
                            })
                            delete this.tableData.tableInfo[0].list
                            delete this.tableData.tableInfo[0].warehousing
                        } else {
                            this.tableData.tableInfo.forEach((item, index) => {
                                if (item.id) {
                                    item.list = _.cloneDeep(item.warehousing);
                                    delete item.warehousing;
                                }
                                let ccisOutStockApplyGoodsDTOList = [];
                                item.list.forEach((items, index) => {
                                    if (!this.loadingInSequence) {
                                        items.seq = '0';
                                    } else {
                                        items.seq = index + 1;
                                    }
                                    ccisOutStockApplyGoodsDTOList.push({
                                        singleWeight: items.singleWeight,
                                        batchAttributeId: items.batchAttributeId,
                                        matName: items.matName,
                                        batchAttr07: items.batchAttr07,
                                        matTypeCode: items.matTypCode,
                                        matCode: items.matCode,
                                        county: items.country,
                                        factoryCode: items.factoryCode,
                                        productStatus: items.productStatus,
                                        inStockDate: items.dateInto,
                                        orderQty: items.totalQtyNew,
                                        isScanSn: items.isScanSn,
                                        codeQty: items.codeQty,
                                        seq: items.seq,
                                        stgTypCode: items.stgTypCode,
                                        wmsBatchNum: items.wmsBatchNum,
                                        cargoOwner: this.tableData.tableInfo.id === undefined || this.tableData.tableInfo.id === null ? this.$utils.getUserInfo().entrustingPartyCode : this.ccisCustomerCode,
                                        settlementCustomer: this.cargoOwner.customerCode
                                    })
                                    // if (this.loadingInSequence) {
                                    //   ccisOutStockApplyGoodsDTOList[index]['seq'] = index + 1;
                                    // }
                                })
                                item['cargoOwner'] = this.tableData.tableInfo.id === undefined || this.tableData.tableInfo.id === null ? this.$utils.getUserInfo().entrustingPartyCode : this.ccisCustomerCode;
                                item['settlementCustomer'] = item.list[0].settlementCustomer;
                                item['status'] = statusCode; //状态
                                item['reason'] = ""; //驳回原因
                                item['driver'] = item.driver;
                                item.ccisOutStockApplyGoodsDTOList = ccisOutStockApplyGoodsDTOList;
                            })
                        }
                        // let isCreted = false;
                        if (this.tableData.tableInfo[0].ccisOutStockApplyGoodsDTOList) {
                            this.tableData.tableInfo[0].ccisOutStockApplyGoodsDTOList.forEach(item => {
                                // if (item.orderQty == 0) {
                                //   this.$Message.warning('出库数量不能为0')
                                if (item.isScanSn == false) {
                                    item.isScanSn = 0
                                } else {
                                    item.isScanSn = 1
                                }
                            })
                        }
                        // if (isCreted == true) {
                        this.tableData.tableInfo[0].ccisOutStockApplyGoodsDTOList.some((item) => {
                            if (item.orderQty != 0) {
                            } else {
                                this.$Message.warning('总库存不能为0')
                                return true;
                            }
                        })
                        if (this.tableData.tableInfo[0].id === undefined || this.tableData.tableInfo[0].id === null) {
                            this.tableData.tableInfo.fileList = this.$refs.attachmentRef.pageData.list;
                            createOutStockApply(this.tableData.tableInfo, this.$props.wmsUrl).then(res => {
                                this.tableData.tableInfo = tableInfo;
                                this.tableData.tableInfoList = tableInfoList;
                                if (res.data.returnCode === 200) {
                                    this.$route.params.tableData = undefined;
                                    this.$Message.success('操作成功');
                                    this.bLoading = false
                                    this.$router.push({
                                        name: 'planInfo',
                                        query: {
                                            planNum: 2
                                        }
                                    })
                                    this.$emit('initData');
                                    this.tableData.tableInfo.forEach((item, index) => {
                                        delete item.list
                                        delete item.boxId
                                    })
                                } else {
                                    this.bLoading = false
                                    this.$Message.warning(res.data.returnMsg);
                                }
                            })
                        } else {
                            this.tableData.tableInfo.fileList = this.$refs.attachmentRef.pageData.list;
                            updateOutStockApply(...this.tableData.tableInfo, this.$props.wmsUrl).then(res => {
                                this.tableData.tableInfoList = tableInfoList;
                                if (res.data.returnCode === 200) {
                                    this.$Message.success('操作成功');
                                    this.bLoading = false
                                    this.$router.push({
                                        name: 'planInfo',
                                        query: {
                                            planNum: 2
                                        }
                                    })
                                    this.$emit('initData');
                                    this.tableData.tableInfo.forEach((item, index) => {
                                        delete item.list
                                        delete item.boxId
                                    })
                                } else {
                                    this.bLoading = false
                                    this.$Message.warning(res.data.returnMsg);
                                }
                            })
                        }
                    }
                })
            } catch {
                this.bLoading = false;
            }
        },
        onIsShows() {
            // this.$route.params.tableData = undefined;
            this.$router.push({
                name: 'planInfo',
                query: {
                    planNum: 2
                },
                params: {
                    menuActiveName: this.$route.query.menuActiveName
                }
            })
            // this.$route.params.menuActiveName = ''
        },
        boxInformation() {
            const boxId = uuidv4()
            this.tableData.tableInfo.push({boxId, list: []})
            this.$set(this.tableData.tableInfo[0], 'carNo', '')
            this.$set(this.tableData.tableInfo[0], 'driver', '')
            this.$set(this.tableData.tableInfo[0], 'tel', '')
            this.$set(this.tableData.tableInfo[0], 'outEstimateDate', '')
        },
        boxDelete(scope, rows) {
            rows.splice(scope.$index, 1)
            if (scope.row.list[0]) {
                if (scope.row.list[0].goodsId == this.tableData.tableInfoList[0].goodsId) {
                    this.tableData.tableInfoList = []
                    this.isCreted = fasle;
                }
            }
        },
        handleSelectionChange(val) {
            this.multipleSelection = [];
            if (this.editItem) {
                return;
            }
            this.multipleSelection = val;
        },
        handleSelectionChanges(val) {
            this.multipleSelections = val;
        },
        boxCretedInfo(index, rows) {
            this.$nextTick(() => {
                this.outPlanInfoShow = true
                this.activeRowSelect = rows
                this.activeIndexSelect = index
                if (this.searchInfo.length == 0) {
                    this.getStockListByOwnerCode()
                }
                this.$refs.multipleTables.clearSelection()
                this.$refs.multipleTables.toggleRowSelection(this.activeRowSelect[this.activeIndexSelect], true)
                this.$refs.multipleTable.doLayout();
                if (rows[index].list.length == 0) {
                    this.selectInfo = [];
                    this.getStockListByOwnerCode();
                } else {
                    this.selectInfo = _.cloneDeep(rows[index].list);
                }
            })
        },
        boxDtailDelete(scope) {
            this.tableData.tableInfoList.splice(scope.$index, 1)
            this.selectInfo.splice(scope.$index, 1)
        },
        handleOnChange(row, index) {
            this.tableData.tableInfoList = [];
            this.selectRow = row;
            if (row.list && row.list.length > 0) {
                this.tableData.tableInfoList = row.list;
            }
        },
        goodsInformation() {
            this.tableData.tableInfoList = [];
            this.totalQtyHandler()
            if (this.editItem) {
                if (this.closeAdd) {
                    this.outPlanInfoShow = false
                    this.selectInfo.forEach((item) => {
                        if (item.isScanSn != 1) {
                            item['isScanSn'] = '0'
                        }
                    })
                    this.selectInfo.forEach(item => {
                        this.tableData.tableInfoList.push(item);
                    })
                } else {
                    this.$Message.error('出库数量不能大于可出库数量')
                }
            } else {
                if (this.closeAdd) {
                    this.outPlanInfoShow = false
                    this.selectInfo.forEach((item) => {
                        if (item.isScanSn != 1) {
                            item['isScanSn'] = '0'
                        }
                    })
                    this.selectInfo.forEach(item => {
                        item.goodsId = uuidv4();
                    });
                    this.tableData.tableInfo[this.activeIndexSelect].list = _.cloneDeep(this.selectInfo);
                    this.tableData.tableInfoList = _.cloneDeep(this.selectInfo);
                    this.$refs.multipleTables.clearSelection()
                    this.$refs.multipleTables.toggleRowSelection(this.activeRowSelect[this.activeIndexSelect], true)
                } else {
                    this.$Message.error('出库数量不能大于可出库数量')
                }
            }
            this.$nextTick(() => {
                this.$refs.multipleTable.doLayout();
            })
        },
        getBoxInfoDtail() {
            let body = {
                pageNum: 1,
                pageSize: 50,
                pageOptionsList: [
                    50,
                    100,
                    200
                ],
                filterList: [],
                sortList: [],
                searchKey: "",
                searchOrderType: "",
                searchOrderTypeList: [],
                notInMatTypeCodeList: [
                    "9999",
                    "0001"
                ]
            }
            getBoxInfoWarehousing(body, this.$props.wmsUrl).then(({data}) => {
                console.log(data)
            })
        },
        batchDelete() {
            this.multipleSelection.forEach(item => {
                for (let i = 0; i < this.tableData.tableInfo.length; i++) {
                    if (item.boxId == this.tableData.tableInfo[i].boxId) {
                        if (this.tableData.tableInfo[i].list[0]) {
                            if (this.tableData.tableInfo[i].list[0].goodsId == this.tableData.tableInfoList[0].goodsId) {
                                this.tableData.tableInfoList = []
                                this.isCreted = fasle;
                            }
                        }
                        this.tableData.tableInfo.splice(i, 1);
                    }
                }
            })
        },
        batchDeletes() {
            for (let j = 0; j < this.multipleSelections.length; j++) {
                for (let i = 0; i < this.tableData.tableInfoList.length; i++) {
                    if (this.multipleSelections[j].goodsId == this.tableData.tableInfoList[i].goodsId) {
                        this.tableData.tableInfoList.splice(i, 1);
                    }
                }
            }
        },
        getInfoInte() {
            getBusinessInfo(this.$props.wmsUrl).then(res => {
                this.businessList = res.data.returnData
            })
            getCategoryInfo(this.$props.wmsUrl).then(res => {
                this.categoryList = res.data.returnData
            })
        },
        getInfoName() {
            baseCodeApi.getContractDictData().then(({data}) => {
                if (data.returnCode === 200) {
                    const {platformWarehouseList, customerList} = data.returnData;
                    this.dictInfo.whCode = platformWarehouseList.map(i => {
                        return {
                            dictName: i.whName,
                            dictValue: i.id
                        };
                    });
                    this.dictInfo.customerId = customerList.map(i => {
                        return {
                            dictName: i.customerName,
                            dictValue: i.id,
                            customerCode: i.customerCode
                        };
                    });
                    this.cargoOwner = this.dictInfo.customerId.filter(item => item.dictValue == this.$utils.getUserInfo().entrustingParty)[0]
                    this.settlementCustomer = this.cargoOwner.dictValue
                    this.selectCustomer = _.cloneDeep(this.cargoOwner.dictValue)
                    this.selectCustomerCode = _.cloneDeep(this.cargoOwner.customerCode)
                    this.selectCustomerInfoByDto();
                } else {
                    this.$Message.error(data.returnMsg);
                }
            }).catch(err => {
                console.log(err);
            });
        },
        getOwnerCodeListByStock() {
            let body = {
                filterList: [
                    {
                        filterKey: "whCode",
                        filterValue: ""
                    },
                    {
                        filterKey: 'ownerCode',
                        filterValue: this.$props.ccisCustomerCode
                    },
                    {
                        filterKey: 'supervisionStatus',
                        filterValue: '0'
                    }
                ],
                filterName: [],
                stkCodeList: [],
                pageNum: this.page,
                pageSize: this.pageSize,
                pageOptionsList: [
                    50,
                    100,
                    200
                ],
                searchKeyOrderType: null,
                sortList: [],
                searchKey: "",
                searchOwnerCode: this.ccisCustomerCode,
                searchWhCode: '',
                searchSettlementCustomer: '',
                searchManageCompanyCode: '',
                outPlanOrderNum: ""
            }
            getOwnerCodeListByStock(body, this.$props.wmsUrl).then(({data}) => {
                if (data.returnCode == 200) {
                    this.allOwner = data.returnData
                }
            })
        },
        checkData() {
            if (!this.selectRow) {
                this.$Message.warning('请先选择一条出库车辆信息');
                return false;
            }
            this.$refs.attachmentRef.showUpload();
        },
        refreshFileList(row, fileList) {
            this.tableData.tableInfo.forEach(item => {
                if (row.boxId == item.boxId) {
                    item.fileList = fileList;
                }
            })
        },
        getWmsCustomerList() {
          getByCustomerType({customerProperty: 'h'}, this.$props.wmsUrl).then(response => {
            if (response.data.returnCode === 200) {
              this.wmsCustomerList = response.data.returnData;
            } else {
              this.$Message.error(response.data.returnMsg);
            }
          });
        },
        selectCustomerChange() {
          this.cargoOwner = this.dictInfo.customerId.filter(item => item.dictValue == this.selectCustomer)[0]
          this.selectCustomerCode = _.cloneDeep(this.cargoOwner.customerCode)
          this.selectCustomerInfoByDto();
        }
    },
    mounted() {
        this.$props.menuActiveName = JSON.parse(this.$route.query.menuActiveName)
            this.$props.wareList = JSON.parse(this.$route.query.wareList)
            this.$props.wmsUrl = JSON.parse(this.$route.query.wmsUrl)
            this.$props.ccisCustomerCode = JSON.parse(this.$route.query.ccisCustomerCode)
        if (!this.$props.wmsUrl) {
            this.$props.wmsUrl = this.wareList.filter(item => item.id == this.$route.params.menuActiveName)[0].ipProt;
        }
        if (this.$route.query.editStatus) {
            this.$props.editStatus = JSON.parse(this.$route.query.editStatus)
        }
        if (this.$route.query.editItem) {
            this.$props.editItem = JSON.parse(this.$route.query.editItem)
        }
        if (this.$route.query.editItemWarehousing) {
            this.$props.editItemWarehousing = JSON.parse(this.$route.query.editItemWarehousing)
        }
        if (this.$route.query.tableData) {
            this.tableDataCK = _.cloneDeep(JSON.parse(this.$route.query.tableData))
        }
        this.whList = [{
            label: this.wareList.filter(item => item.id == this.menuActiveName)[0].whName,
            value: this.wareList.filter(item => item.id == this.menuActiveName)[0].whCode
        }]
        if (this.editItem !== null && this.editItemWarehousing !== undefined) {
            let editItem = _.cloneDeep(this.editItem)
            let editItemWarehousing = _.cloneDeep(this.editItemWarehousing)
            if (editItemWarehousing.isScanSn == 0) {
                editItemWarehousing.isScanSn = false;
            } else {
                editItemWarehousing.isScanSn = true;
            }
            editItemWarehousing.dateInfo = this.$utils.timestampToDate(editItemWarehousing.dateInfo)
            if (this.editItem) {
                editItemWarehousing.forEach((item) => {
                    if (item.seq != '0') {
                        this.loadingInSequence = true
                    } else {
                        this.loadingInSequence = false
                    }
                    item.totalQtyNew = item.totalQty
                    item.dateInto = this.$utils.timestampToDate(item.dateInto);
                    item.dateGen = this.$utils.timestampToDate(item.dateGen);
                    item.dateExpire = this.$utils.timestampToDate(item.dateExpire);
                    this.tableData.tableInfoList.push(item);
                    this.selectInfo.push(item);
                })
                editItem.list = this.selectInfo;
                this.tableData.tableInfo.push(editItem);
            }
            if (this.tableData.tableInfo[0].fileList && this.tableData.tableInfo[0].fileList.length > 0) {
                this.$nextTick(() => {
                    this.selectRow = {fileList: this.tableData.tableInfo[0].fileList};
                });
            }
        }
        if (this.$route.query.tableData) {
            if (this.tableDataCK != undefined) {
                let tableDataCKNew = []
                const boxId = uuidv4()
                this.tableData.tableInfo.push({boxId, list: []})
                this.tableDataCK.forEach((item, index) => {
                    item.dateInto = this.$utils.timestampToDate(item.dateInto);
                    item.dateGen = this.$utils.timestampToDate(item.dateGen);
                    item.dateExpire = this.$utils.timestampToDate(item.dateExpire);
                    if (item.availableQty > 0) {
                        tableDataCKNew.push(item)
                    }
                })
                this.tableData.tableInfo[0].list = _.cloneDeep(tableDataCKNew);
                this.tableData.tableInfo[0].list.forEach((item) => {
                    item['totalQtyNew'] = item.availableQty
                    this.$nextTick(() => {
                        item.isScanSn = false
                    })
                })
                this.tableData.tableInfoList = this.tableData.tableInfo[0].list
                // this.$refs.multipleTable.doLayout();
                this.$nextTick(() => {
                    this.$refs.multipleTables.toggleAllSelection();
                })
            }
        }
        this.getInfoInte()
        this.getInfoName()
        this.selectCustomerInfoByDto()
        this.getOwnerCodeListByStock()
        this.getWmsCustomerList()
      },
      watch: {
        '$store.state.user.userInfo': {
          handler(value) {
            console.log(value)
            if (!value || !value.entrustingPartyCode) return;
            if (this.customerInfoList.length === 1) {
              this.selectCustomer = this.customerInfoList[0].customerPartyID
              this.settlementCustomer = _.cloneDeep(this.customerInfoList[0].customerPartyID)
              this.selectCustomerCode = this.customerInfoList[0].customerCode
            }
          },
          deep: true,
          immediate: true
        }
      },
      computed: {
        customerInfoList() {
          return this.$utils.getUserInfo().customerInfoList || [];
        },
        isCustomerNameInWMS() {
          if (!this.selectCustomer) return true;
          const { customerPartyName } = this.customerInfoList.find(i => i.customerPartyID === this.selectCustomer);
          return this.wmsCustomerList.some(i => i.customerName === customerPartyName);
        }
      }
}
</script>

<style>

</style>
